import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import * as path from 'path'
import viteCompression from 'vite-plugin-compression'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
	base: './',
	build: {
		outDir: '/Users/mcql/Desktop/nginx_project',
		manifest: true,
	},
	plugins: [
		vue(),
		eslintPlugin(),
		viteCompression({
			verbose: true, // 默认即可
			disable: true, //开启压缩(不禁用)，默认即可
			deleteOriginFile: false, //删除源文件
			threshold: 1024, //压缩前最小文件大小
			algorithm: 'gzip', //压缩算法
			ext: '.gz', //文件类型
		}),
		AutoImport({
			resolvers: [ElementPlusResolver()],
		}),
		Components({
			resolvers: [ElementPlusResolver()],
		}),
	],
	resolve: {
		alias: {
			'@': path.resolve(__dirname, 'src'),
		},
	},
	server: {
		port: 8080,
		open: true,
		proxy: {
			'^/api/.*': {
				target: 'http://x.x.x.x:8888',
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/api/, ''),
			},
		},
	},
})
